package com.zrx.utils;

import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 张荣欣
 * @create ：2022/9/16  8:26
 */
public class BeanCopyUtils {

    private BeanCopyUtils(){

    }

    /**
     * 复制数据
     * @param source
     * @param clazz
     * @param <V>
     * @return
     */
    public static <V> V  copyBean(Object source,Class<V> clazz) {

        V result = null;
        try {
            //创建目标对象
            result = clazz.newInstance();
            //实现属性copy
            BeanUtils.copyProperties(source, result);
            //返回结果

        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;

    }


    public static <O,V> List<V>  copyBeanList(List<O> list,Class<V> clazz) {
        return list.stream()
                .map(o -> copyBean(o,clazz))
                .collect(Collectors.toList());


    }

}
